package com.singleton.pattern.singleton.demo;

import java.io.Serializable;

/**
 * @Classname HungrySingleton
 * @Description 饿汉模式
 * @Date 2019/11/20 0020 15:23
 * @Created by 埔枘
 */
public class HungrySingleton implements Serializable {

    private static HungrySingleton hungrySingleton = new HungrySingleton();

    /**
     * 私有化 空构造
     */
    private HungrySingleton(){
        if(hungrySingleton!=null){
            throw new RuntimeException("不能二次实例化对象");
        }
    }

    public static HungrySingleton getSingleton(){
        return hungrySingleton;
    }

    public Object readResolve(){
        return HungrySingleton.hungrySingleton;
    }
}
